<template>
  <div class="container">
      <div class="nav1" v-if="showMedia">
          <div>
              <img src="../../assets/img/热销媒体列表/切图/0.png"><span>类型:</span>
          </div>
          <ul>
              <li v-for="(item,index) in result1" :key="index" @click="changeColor1(index)">
                  <img :src="imgSelect1(index)"><span :class="{red:index1==index,black:index1!=index}">{{item.data_value}}</span>
              </li>
          </ul>
      </div>
      <div class="nav2">
          <div>
              <img src="../../assets/img/热销媒体列表/切图/0.png"><span>领域:</span>
          </div>
          <ul>
              <li v-for="(item,index) in resultBefore" :key="index" @click="changeColor2(index)">
                  <img :src="imgSelect2(index)" alt=""><span :class="{red:index2==index,black:index2!=index}">{{item.data_value}}</span>
              </li>
          </ul>
          <div @click="zk"><img :src="src"><span style="font-size:14px;">{{name}}</span></div>
      </div>
      <div class="nav3">
        <div>
            <img src="../../assets/img/热销媒体列表/切图/0.png"><span>排序:</span>
        </div>
        <ul>
            <li v-for="(item,index) in navList1" :key="index" @click="changeColor3(index)">
                <img :src="item[0]"><span :class="{red:index3==index,black:index3!=index}">{{item[1]}}</span>
            </li>
        </ul>
        <div>
            <input type="text" v-model="input1"  placeholder="请输入关键词进行搜索" @focus="inputFocus"  @blur="inputBlur" :class="{phClass:inputStatus}">
            <div>
                <img src="../../assets/img/热销媒体列表/切图/6.png" alt="" @click="search">
            </div>
        </div>
      </div>
      <div class="content">
        <ul class="list">
            <li v-for="(item,index) in result3" :key="index" style="height:235px;" >
                <ul class="add-border">
                    <li>
                        <img :src="item.logo" width="90px" height="90px" style="border-radius:50%;">
                        <img :src="smallIcon" width="26px" height="26px">
                    </li>
                    <li>
                        <p>{{title1(index)}}</p>
                        <p>{{content1(index)}}</p>
                    </li>
                    <li>
                        <p>所属类别</p>
                        <p>{{type}}</p>
                    </li>
                    <li>
                        <p>{{title2}}</p>
                        <p>{{content2(index)}}</p>
                    </li>
                    <li>
                        <p>{{title3}}</p>
                        <p>{{content3(index)}}</p>
                    </li>
                    <li>
                        <p>{{title4}}</p>
                        <p>{{content4(index)}}</p>
                    </li>
                    <li>
                        <p>参考价格</p>
                        <p>{{content5(index)}}元起</p>
                    </li>
                    <li class="add-position">
                        <div><button @click="addctrl(index)">{{ctrlName}}</button></div>
                        <div><button @click="$router.push({path:'/view2/shortVideoDetail',query:{id:item.id }})">查看详情</button></div>
                    </li>
                </ul>
            </li>
        </ul>
        <div>
        <el-pagination class="page"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
        </div>
        <br>
      </div>
  </div>
</template>
<script>
const img1 = require("../../assets/img/热销媒体列表/切图/1.png");
const img2 = require("../../assets/img/热销媒体列表/切图/2.png");
const img4 = require("../../assets/img/热销媒体列表/切图/4.png");
const img8 = require("../../assets/img/热销媒体列表/切图/8.png");
const img5 = require("../../assets/img/热销媒体列表/切图/5.png");
const img9 = require("../../assets/img/热销媒体列表/切图/9.png");
const img10 = require("../../assets/img/收藏夹/切图/4.png");
const img11 = require("../../assets/img/收藏夹/切图/5.png");
const img12 = require("../../assets/img/收藏夹/切图/6.png");
const img13 = require("../../assets/img/收藏夹/切图/7.png");
const img14 = require("../../assets/img/收藏夹/切图/8.png");
export default {
  data() {
    return {
      // 判断是否从APP矩阵进入的
      showMedia: true,
      navList1: [
        [img5, "综合", img9],
        [img5, "人气", img9],
        [img5, "价格", img9]
      ],
      index3: 0,
      input1: "",
      // 列表一需要显示默认进行勾选的。
      index1: 0,
      // 列表一需要显示默认进行勾选的。
      index2: 0,
      // 路由参数type，默认勾选
      type: "",
      // 查询结果1
      result1: "",
      // 查询结果2
      result2: "",
      // 查询结果3
      result3: "",
      // 展开显示数据
      resultBefore: "",
      // 默认勾选样式
      imgDef: img1,
      // 选中样式
      imgCli: img2,
      name: "点击展开",
      src: img8,
      key: 6,
      page: 1,
      limit: 10,
      order: "",
      sort: "ASC",
      orderList: ["03", "01", "02"],
      smallIcon: "",
      // 分页总条数
      total: 0,
      ctrlName: "加入收藏夹",
      inputStatus : false,
    };
  },
  computed: {
    args() {
      return {
        type: this.type,
        page: this.page,
        limit: this.limit,
        dicCode: "002",
        dataKey: this.key,
        order: this.order,
        sort: this.sort
      };
    }
  },
  methods: {
    // 搜素功能
    search() {
      this.$ajax
        .post(this.Ipurl + "popularMedia/search", {
          page: this.page,
          limit: this.limit,
          str: this.input1
        })
        .then(res => {
          if (res.data.returnCode == 1000) {
            this.total = res.data.dataInfo.total;
            this.result3 = res.data.dataInfo.records;
            this.typeData();
          } else {
            this.$message.error("没有查询到搜索信息");
          }
        });
    },
    changeColor3(index) {
      // img9为降序标识
      if (this.navList1[index][0] == img5) {
        this.navList1[index][0] = img9;
      } else {
        this.navList1[index][0] = img5;
      }
      this.index3 = index;
      if (this.navList1[index][0] == img9) {
        this.sort = "DESC";
      } else {
        this.sort = "ASC";
      }
      this.order = this.orderList[index];
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.total = res.data.dataInfo.total;
          this.result3 = res.data.dataInfo.records;
          this.typeData();
        });
    },
    // 进行单击的时候改变值和文字样式控制
    changeColor1(index) {
      this.index1 = index;
      this.type = this.result1[index]["data_value"];
      // console.log(this.args);
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.total = res.data.dataInfo.total;
          this.result3 = res.data.dataInfo.records;
          this.typeData();
        });
    },
    // 图片样式控制
    imgSelect1(index) {
      if (index == this.index1) {
        return this.imgDef;
      } else {
        return this.imgCli;
      }
    },
    changeColor2(index) {
      this.index2 = index;
      this.key = this.result2[index]["data_key"];
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.total = res.data.dataInfo.total;
          this.result3 = res.data.dataInfo.records;
          this.typeData();
        });
    },
    imgSelect2(index) {
      if (index == this.index2) {
        return this.imgDef;
      } else {
        return this.imgCli;
      }
    },
    zk() {
      if (this.name == "点击展开") {
        this.name = "点击收起";
        this.src = img4;
        this.resultBefore = this.result2;
      } else {
        this.name = "点击展开";
        this.src = img8;
        this.resultBefore = this.result2.slice(0, 6);
      }
    },
    // 分页--条数
    handleSizeChange(val) {
      this.limit = val;
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.result3 = res.data.dataInfo.records;
          this.typeData();
        });
    },
    // 分页--页数
    handleCurrentChange(val) {
      this.page = val;
      this.$ajax
        .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
        .then(res => {
          this.result3 = res.data.dataInfo.records;
          this.typeData();
        });
    },
    // 根据类型封装显示数据
    typeData() {
      if (this.type == "短视频") {
        this.title2 = "所属平台";
        this.title3 = "ID";
        this.title4 = "粉丝数";
        this.smallIcon = img10;
      } else if (this.type == "小红书号") {
        this.title2 = "粉丝数";
        this.title3 = "点赞/收藏";
        this.title4 = "笔记数量";
        this.smallIcon = img11;
      } else if (this.type == "网易考拉海购号") {
        this.title2 = "获赞量";
        this.title3 = "粉丝数";
        this.title4 = "文章数";
        this.smallIcon = img12;
      } else if (this.type == "微信公众号") {
        this.title2 = "ID";
        this.title3 = "平均阅读量";
        this.title4 = "粉丝数";
        this.smallIcon = img13;
      } else if (this.type == "微博大V号") {
        this.title2 = "粉丝数";
        this.title3 = "平均转发量";
        this.title4 = "平均点赞量";
        this.smallIcon = img14;
      }
    },
    title1(index) {
      return this.result3[index].mediaName;
    },
    content1(index) {
      return this.result3[index].about;
    },
    content2(index) {
      if (this.type == "短视频") {
        return this.result3[index].platformName;
      } else if (this.type == "小红书号") {
        return this.numLen(this.result3[index].fansTotal + "");
      } else if (this.type == "网易考拉海购号") {
        return this.numLen(this.result3[index].likenumInt + "");
      } else if (this.type == "微信公众号") {
        return this.result3[index].userId;
      } else if (this.type == "微博大V号") {
        return this.numLen(this.result3[index].fansTotal + "");
      }
    },
    content3(index) {
      if (this.type == "短视频") {
        return this.result3[index].userId;
      } else if (this.type == "小红书号") {
        return this.numLen(this.result3[index].likenumInt + "");
      } else if (this.type == "网易考拉海购号") {
        return this.numLen(this.result3[index].fansTotal + "");
      } else if (this.type == "微信公众号") {
        return this.numLen(this.result3[index].readingQuantity + "");
      } else if (this.type == "微博大V号") {
        return this.numLen(this.result3[index].amountOfForwarding + "");
      }
    },
    content4(index) {
      if (this.type == "短视频") {
        return this.numLen(this.result3[index].fansTotal + "");
      } else if (this.type == "小红书号") {
        return this.numLen(this.result3[index].noteTheNumber + "");
      } else if (this.type == "网易考拉海购号") {
        return this.numLen(this.result3[index].articleNum + "");
      } else if (this.type == "微信公众号") {
        return this.numLen(this.result3[index].fansTotal + "");
      } else if (this.type == "微博大V号") {
        return this.numLen(this.result3[index].likenumInt + "");
      }
    },
    content5(index) {
      return this.result3[index].referencePrice;
    },
    // 收藏夹
    addctrl(index) {
        // 是否登录，加入收藏夹
        if (window.sessionStorage.getItem("userInfo")) {
            this.$ajax
              .post(this.Ipurl + "favoriteInfo/save", {
                userId: JSON.parse(window.sessionStorage.getItem("userInfo"))
                  .userId,
                popularMediaId: this.result3[index].id,
                type: this.result3[index].type
              })
              .then(res => {
                if (res.data.returnCode == 1000) {
                  this.$message("添加成功");
                }else if(res.data.returnCode==2000){
                  this.$message("sorry!已经收藏了")
                } else {
                  this.$message.error("添加失败");
                }
              });
        } else {
          this.$confirm("检测到您并没有登录", "warning", {
            confirmButtonText: "立即登录",
            cancelButtonText: "不了，谢谢",
            type: "warning"
          }).then(() => {
            this.$router.push("/login");
          });
        }
      },
      inputFocus(){
        this.inputStatus = true;
      },
      inputBlur(){
        this.inputStatus = false;
      },
  },
  mounted() {
    // 判断有参数的路由的地方进行跳转
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
      // 读取列表一
      this.$ajax
        .post(
          this.Ipurl + "sysdictionarydata/getValueListByCode" + "?dicCode=001"
        )
        .then(res => {
          this.result1 = res.data.dataInfo;
          // 根据传入的类别判断显示哪一个。
          for (let i = 0; i < this.result1.length; i++) {
            if (this.result1[i]["data_value"] == this.type) {
              this.index1 = i;
            }
          }
          // 读取列表二
          this.$ajax
            .post(
              this.Ipurl +
                "sysdictionarydata/getValueListByCode" +
                "?dicCode=002"
            )
            .then(res => {
              this.result2 = res.data.dataInfo;
              // 显示前6个
              this.resultBefore = this.result2.slice(0, 6);
              // 读取默认内容数据
              this.$ajax
                .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
                .then(res => {
                  this.total = res.data.dataInfo.total;
                  this.result3 = res.data.dataInfo.records;
                  this.typeData();
                });
            });
        });
    } else {
      //不是从路由的地方跳转
      this.$ajax
        .post(
          this.Ipurl + "sysdictionarydata/getValueListByCode" + "?dicCode=001"
        )
        .then(res => {
          this.result1 = res.data.dataInfo;
          // 默认取第一个
          this.type = this.result1[0]["data_value"];
          this.index1 = 0;
          // 读取列表二
          this.$ajax
            .post(
              this.Ipurl +
                "sysdictionarydata/getValueListByCode" +
                "?dicCode=002"
            )
            .then(res => {
              this.result2 = res.data.dataInfo;
              this.resultBefore = this.result2.slice(0, 6);
              this.$ajax
                .post(this.Ipurl + "popularMedia/selectListByKey", this.args)
                .then(res => {
                  this.total = res.data.dataInfo.total;
                  this.result3 = res.data.dataInfo.records;
                  this.typeData();
                });
            });
        });
    }
  }
};
</script>

<style scoped>
.container {
  width: 1200px;
  margin: 0 auto;
  margin-top: 50px;
  overflow: hidden;
  background: #fff;
}
.nav1 {
  overflow: hidden;
}
.nav1 > div {
  float: left;
  width: 150px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.nav1 > div > span {
  margin-left: 20px;
  font-size: 16px;
  font-weight: bold;
}
.nav1 > ul {
  float: left;
  overflow: hidden;
}
.nav1 > ul > li {
  float: left;
  width: 170px;
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  cursor: pointer;
}
.nav1 > ul > li > span {
  margin-left: 5px;
}
.nav1 > ul > li > span.red {
  color: rgb(237, 64, 64);
}
.nav1 > ul > li > span.black {
  color: rgb(34, 34, 34);
}
.nav2{
  overflow: hidden;
   border-top:15px solid #f8f9fd;
}
.nav2 > div {
  float: left;
  width: 150px;
  height: 60px;
  line-height: 50px;
  text-align: center;

  overflow: hidden;
}
.nav2 > div > span {
  margin-left: 20px;
  font-size: 16px;
  font-weight: bold;
}
.nav2 > ul {
  float: left;
  /* overflow: hidden; */
  width: 1050px;
}
.nav2 > ul > li {
  float: left;
  width: 170px;
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  cursor: pointer;
  /* overflow: hidden; */
}
.nav2 > ul > li > span {
  margin-left: 10px;
}
.nav2 > ul > li > span.red {
  color: rgb(237, 64, 64);
}
.nav2 > ul > li > span.black {
  color: rgb(34, 34, 34);
}
.nav2 > div:nth-child(3) {
  width: 100%;
  text-align: center;
  height: 24px;
  line-height: 24px;
  background: rgb(237, 64, 64);
  cursor: pointer;
}
.nav2 > div:nth-child(3) > span {
  font-size: 16px;
  color: #fff;
  margin-left: 8px;
}
.nav2 > div:nth-child(3) > img {
  margin-top: -5px;
}
.content {
  width: 1200px;
  margin: 0 auto;
  /* margin-top: 20px; */
  overflow: hidden;
}
.list {
  overflow: hidden;
}
.list > li > ul > li {
  float: left;
  height: 200px;
  margin-top: 20px;
  background: #fff;
}
.list > li > ul > li:nth-child(1) {
  width: 190px;
  text-align: center;
  line-height: 200px;
  position: relative;
}
.list > li > ul > li:nth-child(1) > img:nth-child(2) {
  /* 下侧小图 */
  position: absolute;
  top: 115px;
  right: 50px;
}
.list > li > ul > li:nth-child(2) {
  width: 285px;
}
.list > li > ul > li:nth-child(2) > p:nth-child(1) {
  font-size: 18px;
  font-weight: bold;
  margin-top: 76px;
}
.list > li > ul > li:nth-child(2) > p:nth-child(2) {
  font-size: 14px;
  font-weight: bold;
  margin-top: 20px;
  color: rgb(34, 34, 34);
}
.list > li > ul > li:nth-child(3),
.list > li > ul > li:nth-child(4),
.list > li > ul > li:nth-child(5),
.list > li > ul > li:nth-child(6),
.list > li > ul > li:nth-child(7) {
  width: 100px;
  height: 200px;
  text-align: center;
}
.list > li > ul > li > p:nth-child(1) {
  font-size: 14px;
  font-weight: bold;
  margin-top: 76px;
}
.list > li > ul > li > p:nth-child(2) {
  font-size: 16px;
  font-weight: bold;
  margin-top: 20px;
  color: rgb(237, 64, 64);
}
.list > li > ul > li:last-child {
  width: 200px;
}
.list > li > ul > li:last-child > div {
  text-align: center;
}
.list > li > ul > li:last-child > div:nth-child(2) > button {
  width: 100px;
  height: 30px;
  border: 1px solid rgb(34, 34, 34);
  border-radius: 15px;
  margin-top: 16px;
  font-size: 14px;
  font-weight: bold;
  background: #fff;
}
.list > li > ul > li:last-child > div:nth-child(1) > button {
  width: 100px;
  height: 30px;
  border-radius: 15px;
  margin-top: 20px;
  color: #fff;
  background: rgb(237, 64, 64);
  font-size: 14px;
  font-weight: bold;
}
.page {
  padding-left: 250px;
  margin-top:3px;
  margin-bottom:15px;
  /* border-top:3px solid #eee; */
}
.nav3 {
  width: 1200px;
  margin: 0 auto;
  /* margin-top: 20px; */
  overflow: hidden;
  background: #fff;
  border-top:15px solid #f8f9fd;
}
.nav3 > div:nth-child(1) {
  float: left;
  width: 150px;
  height: 60px;
  line-height: 60px;
  text-align: center;
}
.nav3 > div:nth-child(1) > span {
  margin-left: 20px;
  font-size: 16px;
  font-weight: bold;
}
.nav3 > ul {
  float: left;
  overflow: hidden;
}
.nav3 > ul > li {
  float: left;
  width: 170px;
  height: 60px;
  line-height: 60px;
  font-size: 16px;
  cursor: pointer;
}
.nav3 > ul > li > span {
  margin-left: 10px;
}
.nav3 > ul > li > span.red {
  color: rgb(237, 64, 64);
}
.nav3 > ul > li > span.black {
  color: rgb(34, 34, 34);
}
.nav3 > div:nth-child(3) {
  float: right;
  position: relative;
}
.nav3 > div:nth-child(3) > input {
  width: 268px;
  height: 32px;
  border: 1px solid rgb(237, 64, 64);
  margin-top: 10px;
  margin-right: 50px;
  border-radius: 5px 0 0 5px;
  padding-left: 15px;
  color:#c6c6c6;
}
.nav3 > div:nth-child(3) >input::-webkit-input-placeholder{
             color:#c6c6c6;
        }
.nav3 > div:nth-child(3) > div {
  width: 32px;
  height: 32px;
  text-align: center;
  line-height: 32px;
  position: absolute;
  top: 10px;
  right: 18px;
  border-radius: 0 5px 5px 0;
  cursor: pointer;
  background: rgb(237, 64, 64);
  /* font-weight: 700 */
}
.add-border{
  border-top:15px solid #f8f9fd;
 position: relative;
}
.add-position{
position:absolute;
right:15px;
top:45px;
}


.nav3 > div:nth-child(3) > .phClass::-webkit-input-placeholder { /* WebKit, Blink, Edge */
    color: transparent
}
.nav3 > div:nth-child(3) > .phClass:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
   color: transparent
}
.nav3 > div:nth-child(3) > .phClass::-moz-placeholder { /* Mozilla Firefox 19+ */
   color: transparent
}
.nav3 > div:nth-child(3) > .phClass:-ms-input-placeholder { /* Internet Explorer 10-11 */
   color: transparent
}
</style>




